/*******************************************************************************
  Name: limits.h
  Copyright: Kieran Foot 2009
  Author: Kieran Foot
  Date: 12/06/09 15:44
  Description: Describes the maximum and minimum number a variable can hold
*******************************************************************************/

#include <_ansi.h>
#include <MGOS.h>

#ifndef __LIMITS_H__
#define __LIMITS_H__

_BEGIN_STD_C

#ifndef MGOS_TARGET_BITS
    #define MGOS_TARGET_BITS 32 // Default to 32 bit architecture
#endif

#undef MB_LEN_MAX 
#undef CHAR_BIT
#undef SCHAR_MIN
#undef SCHAR_MAX
#undef UCHAR_MAX 
#undef CHAR_MIN
#undef CHAR_MAX
#undef SHRT_MIN
#undef SHRT_MAX
#undef USHRT_MAX
#undef INT_MIN
#undef INT_MAX
#undef UINT_MAX

// NOTE: This corresponds to the typedef wchar_t in stddef.h
#define MB_LEN_MAX           (MGOS_WIDE_CHAR_SIZE / 8)

#define CHAR_BIT             8
#define SCHAR_MIN            -128
#define SCHAR_MAX            127
#define UCHAR_MAX            255
#define CHAR_MIN             -128
#define CHAR_MAX             127
#define SHRT_MIN             -32768
#define SHRT_MAX             32767
#define USHRT_MAX            65535
#define INT_MIN              -2147483648
#define INT_MAX              2147483647
#define UINT_MAX             4294967295

#undef LONG_MIN
#undef LONG_MAX
#undef ULONG_MAX
#undef LLONG_MIN
#undef LLONG_MAX
#undef ULLONG_MAX

#if MGOS_TARGET_BITS == 32
    #define LONG_MIN         -2147483648L
    #define LONG_MAX         2147483647L
    #define ULONG_MAX        4294967295UL
#elif MGOS_TARGET_BITS == 64
    #define LONG_MIN         -9223373036854775808LL
    #define LONG_MAX         9223373036854775807LL
    #define ULONG_MAX        18446744073709551615ULL
#endif

#define LLONG_MIN        -9223373036854775808LL
#define LLONG_MAX        9223373036854775807LL
#define ULLONG_MAX       18446744073709551615ULL

_END_STD_C

#endif
